set(PHASAR_VERSION @PHASAR_VERSION@)

@PACKAGE_INIT@
set_and_check(PHASAR_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
set_and_check(PHASAR_LIBRARY_DIR "@PACKAGE_LIBRARY_INSTALL_DIR@")

include (CMakeFindDependencyMacro)

set(PHASAR_LLVM_VERSION @PHASAR_LLVM_VERSION@)

include("${CMAKE_CURRENT_LIST_DIR}/PhasarDepsExports.cmake")
find_dependency(LLVM ${PHASAR_LLVM_VERSION} REQUIRED CONFIG)

set(PHASAR_USE_LLVM_FAT_LIB @USE_LLVM_FAT_LIB@)
set(PHASAR_BUILD_DYNLIB @PHASAR_BUILD_DYNLIB@)
set(PHASAR_USE_Z3 @PHASAR_USE_Z3@)
set(PHASAR_BUILD_MODULES @PHASAR_BUILD_MODULES@)

if (PHASAR_USE_Z3)
  find_dependency(Z3 REQUIRED)
endif()

set(PHASAR_COMPONENTS
  utils
  passes
  config
  db
  pointer
  controlflow

  llvm_utils
  llvm_db
  llvm_pointer
  llvm_typehierarchy
  llvm_controlflow

  taintconfig
  mono
  llvm
  llvm_ifdside
  analysis_strategy
)

list(REMOVE_DUPLICATES phasar_FIND_COMPONENTS)

set(PHASAR_NEEDED_LIBS)

include("${CMAKE_CURRENT_LIST_DIR}/PhasarExports.cmake")

foreach(component ${phasar_FIND_COMPONENTS})
  if(NOT ${component} IN_LIST PHASAR_COMPONENTS)
    set(phasar_FOUND FALSE)
    set(phasar_NOT_FOUND_MESSAGE "Unsupported component: ${component}. Valid components are: ${PHASAR_COMPONENTS}")
  endif()

  list(APPEND PHASAR_NEEDED_LIBS phasar::${component})
endforeach()

if (NOT DEFINED phasar_FOUND)
  set(phasar_FOUND TRUE)
endif()

include(FindPackageHandleStandardArgs)

if (phasar_FOUND)
  if (NOT phasar_FIND_COMPONENTS)
    list(APPEND PHASAR_NEEDED_LIBS phasar::phasar)
    # Default target
    add_library(phasar ALIAS phasar::phasar)
  endif()

  find_package_message(phasar
    "Found phasar: ${PHASAR_LIBRARY_DIR} (found version \"${PHASAR_VERSION}\")"
    "[${PHASAR_LIBRARY_DIR}][${PHASAR_INCLUDE_DIR}]"
  )
else()
  message(STATUS "Could NOT find phasar")
endif()
